<template>
    <div class="article-lists">
        <el-card class="!border-none" shadow="never">

            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="用户姓名">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.keys"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="手机号">
                    <el-input
                        class="w-[280px]"
                        v-model="queryParams.account"
                        clearable
                        @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="认证状态">
                    <el-select class="w-[280px]" v-model="queryParams.status" clearable>
                        <el-option label="全部" :value="0" />
                        <el-option label="认证成功" :value="1" />
                        <el-option label="已被他人绑定" :value="2" />
                        <el-option label="认证中" :value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item label="邀请类型">
                    <el-select class="w-[280px]" v-model="queryParams.is_direct" clearable>
                        <el-option label="全部" :value="0" />
                        <el-option label="直邀" :value="1" />
                        <el-option label="间邀" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="序号(ID)" type="index" :index="indexAdd" min-width="100" />
                <el-table-column label="邀请人用户名" min-width="180" prop="real_name"/>
                <el-table-column label="邀请人手机号" min-width="180" prop="account"/>
                <el-table-column label="邀请人头像" min-width="160" prop="banner_url">
                    <template #default="{ row }">
                        <div class="flex align-middle">
                            <el-image style="width: 38px; height: 38px"
                                    :src="row.avatar"
                                    :zoom-rate="1.2"
                                    :max-scale="7"
                                    :min-scale="0.2" 
                                    fit="contain"
                                    :preview-teleported="true"
                                    :preview-src-list="[row.banner_url]"></el-image>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="是否渠道" min-width="180" prop="is_channel">
                    <template #default="{row}">
                        <span v-if="row.is_channel">是</span>
                        <span v-else>否</span>
                    </template>
                </el-table-column>
                <el-table-column label="认证状态" min-width="180" prop="status ">
                    <template #default="{row}">
                        <span v-if="row.status == 0">认证中</span>
                        <span v-if="row.status == 1">认证成功</span>
                        <span v-if="row.status == 2">已被他人绑定</span>
                        <span v-if="row.status == 3">未认证</span>
                    </template>
                </el-table-column>
                <el-table-column label="邀请类型" min-width="180" prop="invite_type ">
                    <template #default="{row}">
                        <span v-if="row.invite_type == 1">直邀</span>
                        <span v-if="row.invite_type == 2">间邀</span>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="list">
import {agentData,} from '@/api/agent'
import { usePaging } from '@/hooks/usePaging'
const route = useRoute()
const queryParams = reactive({
    user_id: route.query.id ,
    keys: '',
    account: '',
    status: '',
    is_direct: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: agentData,
    params:queryParams
})

const indexAdd = (index: number) => {
    const page = pager.page // 当前页码
    const pagesize = pager.size // 每页条数
    return index + 1 + (page - 1) * pagesize
}

onActivated(() => {
    getLists()
})
route.query.id && getLists()
</script>
